<%--
  Created by IntelliJ IDEA.
  User: 卜加超
  Date: 2018/12/29
  Time: 11:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ include file="/content/variable.jsp" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="/content/common.js"></script>
    <title></title>
    <%@ include file="/content/head.jsp" %>
</head>
<body>
<div class="row">
    <div class="col-md-12">
        <div class="box box-info">
            <div class="box-header with-border">
                <h3 class="box-title">添加视频</h3>
            </div>
            <form id="addInfo" class="form-horizontal" role="form">
                <div class="box-body">

                    <%--欠一个js，先默认为2--%>
                    <div class="form-group">
                        <label for="classificationId" class="col-sm-2 control-label">所属种类</label>
                        <div class="col-sm-8 ">
                            <select id="classificationId" name="classificationId" class="form-control select2"></select>
                        </div>
                    </div>
                    <div class="col-md-offset-5 col-md-9">
                        <button type="submit" class="btn btn-success">确定</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- /.row -->
<%@ include file="/content/js.jsp" %>
<script type="text/javascript">
    $(function () {
        classificationSelect();
        $('#addInfo').bootstrapValidator({
            message: '此值无效',
            fields: {
                    spInfo: {
                        message: '验证分类',
                        validators: {
                            notEmpty: {/*非空提示*/
                                message: '请选择分类',
                            },
                            regexp: {
                                regexp: /^\+?[1-9]\d*$/,// 下拉框选中值大于0
                                message: '',
                            }
                        }
                    }
            }
        }).on('success.form.bv', function (e) {//点击提交之后
            e.preventDefault();
            var $form = $(e.target);
            var bv = $form.data('bootstrapValidator');
            save();
        });
    });
        function classificationSelect() {
            $("#classificationId").select2({
                theme: "bootstrap",
                language: "zh-CN",
                placeholder: "请选择",
                placeholderOption: "first",
                allowClear: true,
                width: 250,
                ajax: {
                    url: "<%=path %>/classification/queryClassification",
                    dataType: 'json',
                    delay: 250,
                    data: function (params) {

                        return {
                            classificationName: params.term,
                        };

                    },
                    processResults: function (data) {
                        return {
                            results: data
                        };
                    },
                    cache: true
                },
                escapeMarkup: function (markup) {
                    return markup;
                },
                minimumInputLength: 0,
                templateResult: formatRepo,
                templateSelection: formatRepoSelection
            });
        }



    function save() {
        modalConfirm("确认要修改所属分类吗？", function (status) {
            if (status) {
                var classificationId= $("#classificationId").select2("val");
                parent.$('#classificationId').val(classificationId);

                var className = $("#classificationId").select2('data');
                parent.$('#classificationName').val(className[0].text);
                layer.closeAll('dialog');

                var index = parent.layer.getFrameIndex(window.name);
                parent.layer.close(index);
            }
        });
    }

</script>
</body>
</html>
